package com.supply.service.impl;

import com.supply.mapper.OutBoundBillMapper;
import com.supply.pojo.OutBoundBill;
import com.supply.pojo.OutBoundBillExample;
import com.supply.service.OutBoundBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OutBoundBillServiceImpl implements OutBoundBillService {
    @Autowired
    private OutBoundBillMapper outBoundBillMapper;
    @Override
    public OutBoundBill queryById(Long id) {
        return outBoundBillMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveOrUpdate(OutBoundBill outBoundBill) {
        if (outBoundBill.getId() == null){
            return outBoundBillMapper.insert(outBoundBill);
        }else {
            return outBoundBillMapper.updateByPrimaryKey(outBoundBill);
        }
    }

    @Override
    public List<OutBoundBill> queryByUserId(Long id) {
        OutBoundBillExample example = new OutBoundBillExample();
        example.createCriteria().andUserIdEqualTo(id);
        return outBoundBillMapper.selectByExample(example);
    }

    @Override
    public List<OutBoundBill> queryByAll() {
        return outBoundBillMapper.selectByExample(null);
    }

    @Override
    public int deleteById(Long id) {

        return outBoundBillMapper.deleteByPrimaryKey(id);
    }
}
